import request from '@/utils/request'
import { ObjectType, ResponseDataPromise } from 'typings/interfaces'
import * as proxy from '@/constants/proxy'
import { Pagination } from '@/components/Records/types'
import axios from 'axios'
import { getToken } from '@/utils/auth'
export interface Params extends ObjectType {
  goodsType?: string
  goodsName?: string
}

export const fetchRecordsRequest = (
  pagination: Omit<Pagination, 'total'>,
  data: Params
): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + '/rm-repair-acceptance/road',
    method: 'post',
    data,
    params: pagination,
  })

export const createRecordRequest = (data: Params): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + '/rm-repair-acceptance',
    method: 'post',
    data,
  })

export const editRecordRequest = (data: Params): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + '/rm-repair-acceptance',
    method: 'patch',
    data,
  })

export const lockRecordRequest = (id: string, lock: '0' | '1') =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + `/bd-tunnel-in/lock`,
    method: 'post',
    data: {
      id,
      lock,
    },
  })

export const deleteRecordsRequest = (ids: string[]) =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + `/rm-repair-acceptance`,
    method: 'delete',
    data: ids,
  })

// 导出
export const exportRecordsRequest = (): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + '/bd-tunnel-in/export',
    method: 'post',
  })

//桥梁子表分页
export const diseasefetchRecordsRequest = (
  pagination: Pagination,
  data: ObjectType
): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + '/rm-repair-acceptance-quantities/page',
    method: 'post',
    data,
    params: {
      page: pagination.pageNum,
      size: pagination.pageSize,
      ...data,
      organId: localStorage.getItem('userInfo')
        ? JSON.parse(localStorage.getItem('userInfo') || '').units[0].id
        : null,
    },
  })
//桥梁子表保存
export const diseasecreateRecordRequest = (data: ObjectType): ResponseDataPromise<string> =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + '/rm-repair-acceptance-quantities',
    method: 'post',
    data,
  })

// 桥梁子表更新
export const diseaseeditRecordRequest = (data: ObjectType): ResponseDataPromise<boolean> =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + '/rm-repair-acceptance-quantities',
    method: 'patch',
    data,
  })

// 桥梁子表删除
export const diseasedeleteRecordsRequest = (ids: string[]): ResponseDataPromise<boolean> =>
  request({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + '/rm-repair-acceptance-quantities',
    method: 'delete',
    data: ids,
  })

// 数据字典
export const innerQueryByMaintanceUnit = (): ResponseDataPromise<any> => {
  return axios({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + '/rm-repair-accept-apply/list',
    method: 'post',
    headers: {
      Authorization: 'Bearer ' + getToken(),
    },
    data: {
      // maintanceUnitId: id ? id.units[0].id : null,
    },
  })
}

// 数据子表数据
export const innerQueryByMaintanceUnitTable = (data: ObjectType): ResponseDataPromise<any> => {
  // alert(1)
  return axios({
    url: proxy.CHECC_AM_ROUTINE_MAINTENANCE + `/rm-repair-accept-apply/${data}`,
    method: 'get',
    headers: {
      Authorization: 'Bearer ' + getToken(),
    },
  })
}
